<!-- @Author: Yu_Bo -->
<template>
	<view class="details">
		<view class="list" v-if="goods_name">
			<view class="img">
				<image :src="image" mode="aspectFill"></image>
			</view>
			<view class="info">
				<view class="title">
					{{goods_name}}
				</view>
				<view class="txt">
					{{author}}/{{press}}
				</view>
				<view class="txt">
					{{isbn}}
				</view>
				<view class="tip">
					{{label}}
				</view>
				<view class="money">
					<view class="left">
						<text class="icon">￥</text>
						<text class="num">{{past_sale_price}}</text>
						<text class="zhe color1">二手{{past_discount}}折</text>
					</view>
				</view>
				<view class="money">
					<view class="left">
						<text class="icon">￥</text>
						<text class="num">{{new_sale_price}}</text>
						<text class="zhe color2">新书{{new_discount}}折</text>
					</view>
				</view>
			</view>
		</view>
		<!--  -->
		<view class="content" v-if="content">
			<view class="con_title">
				<text></text>
				详情介绍
			</view>
			<view class="con_text">
				<u-parse :html="content"></u-parse>
			</view>
		</view>
		<c-footer>
			<view class="footer_btn_two">
				<view class="btn_txt_left" @click="bookBtn">
					<image src="@/static/images/img/home_icon_book.png" mode=""></image>
					<text>书包</text>
				</view>
				<view class="btn_txt color_right page_button" @click="addBtn">
					加入书包
				</view>
			</view>
		</c-footer>
		<!-- sku -->
		<c-booksku ref="sku"></c-booksku>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return{
				id: "",
				image: "",
				goods_name: "",
				author: "",
				press: "",
				isbn: "",
				label: "",
				past_sale_price: "",
				past_discount: "",
				past_label: "",
				past_book_num: "",
				new_sale_price: "",
				new_discount: "",
				new_label: "",
				new_book_num: "",
				content: ""
			}
		},
		computed: {},
		onLoad(opt) {
			this.id = opt.id
			this.getDetails()
		},
		onShow() {},
		methods: {
			// 详情
			getDetails() {
				var that = this
				var params = {
					goods_id: that.id,
				}
				that.$httpApi.bookDetail(params).then((res) => {
					if (res.code == 1) {
						that.image = res.data.image
						that.goods_name = res.data.goods_name
						that.author = res.data.author
						that.press = res.data.press
						that.isbn = res.data.isbn
						that.label = res.data.label
						that.past_sale_price = res.data.past_sale_price
						that.past_discount = res.data.past_discount
						that.past_label = res.data.past_label
						that.past_book_num = res.data.past_book_num
						that.new_sale_price = res.data.new_sale_price
						that.new_discount = res.data.new_discount
						that.new_label = res.data.new_label
						that.new_book_num = res.data.new_book_num
						that.content = res.data.content
					}
				})
			},
			// 书包
			bookBtn() {
				uni.switchTab({
					url: "/pages/book/index"
				})
			},
			// 加入书包
			addBtn() {
				var arr = [
					{
						type: 0,
						id: this.id,
						price: this.past_sale_price,
						discount: this.past_discount,
						label: this.past_label,
						num: this.past_book_num,
					},
					{
						type: 1,
						id: this.id,
						price: this.new_sale_price,
						discount: this.new_discount,
						label: this.new_label,
						num: this.new_book_num,
					}
				]
				this.$refs.sku.openBtn(this.goods_name,arr)
			}
		},
	}
</script>

<style lang='scss' scoped>
	.details {
		width: 100%;
		min-height: 100vh;
		padding: 30rpx;
		background: #f6f6f6;
		
		.list {
			position: relative;
			width: 100%;
			padding: 20rpx;
			background: #fff;
			border-radius: 20rpx;
			display: flex;
			justify-content: space-between;
			
			.img {
				width: 180rpx;
				height: 240rpx;
				
				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
			
			.info {
				width: calc(100% - 180rpx);
				min-height: 240rpx;
				padding-left: 20rpx;
				
				.title {
					width: 100%;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #222222;
				}
				
				.txt {
					width: 100%;
					margin-top: 10rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
				}
				
				.tip {
					width: 100%;
					margin-top: 10rpx;
					padding-bottom: 10rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #00A8FF;
				}
				
				.money {
					width: 100%;
					margin-top: 10rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.left {
						display: flex;
						align-items: center;
						
						.icon {
							padding-top: 5rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 24rpx;
							color: #5A68FF;
						}
						
						.num {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #5A68FF;
						}
						
						.zhe {
							margin-left: 20rpx;
							padding: 2rpx 10rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 22rpx;
							background: #fff;
							border-radius: 10rpx;
						}
						
						.color1 {
							color: #57CB82;
							border: 2rpx solid #57CB82;
						}
						
						.color2 {
							color: #FF9400;
							border: 2rpx solid #FF9400;
						}
					}
					
					.right {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}
			}
		}
		
		.content {
			width: 100%;
			padding: 30rpx 0;
			
			.con_title {
				width: 100%;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #222222;
				display: flex;
				align-items: center;
				
				text {
					display: block;
					width: 8rpx;
					height: 28rpx;
					margin-right: 12px;
					background: #5A68FF;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
				}
			}
			
			.con_text {
				width: 100%;
				padding-top: 30rpx;
			}
		}
	}
	.footer_btn_two {
		width: 100%;
		padding: 20rpx 30rpx 20rpx 0;
		background: #fff;
		display: flex;
		justify-content: space-between;
		
		.btn_txt_left {
			width: 166rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			
			image {
				display: block;
				width: 44rpx;
				height: 44rpx;
			}
			
			text {
				padding-top: 8rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #222222;
			}
		}
		
		.btn_txt {
			width: 524rpx;
			height: 90rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			border-radius: 45rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>